package com.amex.uam.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.amex.uam.dao.AmexUnitDao;
import com.amex.uam.model.AMEX_UNIT;
@Repository("amexUnitDao")
public class AmexUnitDaoImpl extends JdbcDao implements AmexUnitDao {

	@Override
	public boolean updateAmexUnit(AMEX_UNIT unit) {
		final String sql= "select AMEX_UNIT_CD, AMEX_UNIT_DS_TX from AMEX_UNIT where AMEX_UNIT_CD = ?";
		Object[] params= {unit.getAMEX_UNIT_CD()};
		List<AMEX_UNIT> list=this.getJdbcTemplate().query(sql, params, ParameterizedBeanPropertyRowMapper.newInstance(AMEX_UNIT.class));
		if(list==null || list.size()==0){
			final String insertSql= "insert into AMEX_UNIT(AMEX_UNIT_CD, AMEX_UNIT_DS_TX) values(?, ?)";
			Object[] insertParams={unit.getAMEX_UNIT_CD(), unit.getAMEX_UNIT_DS_TX()};
			this.getJdbcTemplate().update(insertSql, insertParams);
		}else{
			final String updateSql= "update AMEX_UNIT set AMEX_UNIT_DS_TX = ? where AMEX_UNIT_CD = ?";
			Object[] updateParams={unit.getAMEX_UNIT_DS_TX(), unit.getAMEX_UNIT_CD()};
			this.getJdbcTemplate().update(updateSql, updateParams);
		}
		return true;
	}
}
